package com.intelligence.tio.server.handler;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.core.Aio;
import org.tio.core.ChannelContext;
import org.tio.json.Json;

import com.intelligence.tio.common.Command;
import com.intelligence.tio.common.JsonPacket;
import com.intelligence.tio.common.TioSessionContext;
import com.intelligence.tio.common.intf.AbsTioBsHandler;
import com.intelligence.tio.common.packages.DataErrorRespBody;
import com.intelligence.tio.common.packages.GroupMsgReqBody;
import com.intelligence.tio.common.packages.HeartBeatReqBody;
import com.intelligence.tio.common.packages.HeartBeatRespBody;

/**
 * 
* @Title: HeartbeatReqHandler.java 
* @Package com.intelligence.tio.server.handler 
* @Description: 心跳包消息处理器
* @Company: 南京因坦利软件有限公司
* @author 郭浩柱  
* @date 2017年5月18日 下午3:31:04 
* @version V1.0
 */
public class HeartbeatReqHandler extends AbsTioBsHandler<HeartBeatReqBody>
{
	private static Logger log = LoggerFactory.getLogger(HeartbeatReqHandler.class);

	/**
	 * 
	 * @author: tanyaowu
	 */
	public HeartbeatReqHandler()
	{
	}
	
	@Override
	public Class<HeartBeatReqBody> bodyClass()
	{
		return HeartBeatReqBody.class;
	}

	/** 
	 * @param packet
	 * @param bsBody
	 * @param channelContext
	 * @return
	 * @throws Exception
	 * @author: tanyaowu
	 */
	@Override
	public Object handler(JsonPacket packet, HeartBeatReqBody bsBody, ChannelContext<TioSessionContext, JsonPacket, Object> channelContext) throws Exception
	{
		log.debug("接受到客户端心跳包");
		//心跳消息，返回心跳包响应码
		HeartBeatRespBody body = new HeartBeatRespBody();
		body.setCommand(Command.COMMAND_HEARTBEAT_RESP.getValue());
		JsonPacket respPacket = new JsonPacket();
		respPacket.setBody(Json.toJson(body).getBytes(JsonPacket.CHARSET));
		Aio.send(channelContext, respPacket);
		return null;
	}
}
